<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		
		<script type="text/javascript">
			// 用户第一次访问，询问一下名字，cookie保存
			// 用户第二次访问，询问一下名字，cookie保存
			
			console.log(document.cookie);
			if(document.cookie.length>0)
			{
				var str = document.cookie; // count=1;name=zhangsan
				var name = str.substr(str.indexOf("name=")+5);
				name = name.substr(0,name.indexOf(";"));
				console.log(name);
				
				var count = str.substr(str.indexOf("count=")+6);
				console.log(count);
				count++;
				
				document.write("欢迎"+name+",第"+count+"次光临")
				
				var now = new Date();
				now.setMinutes(now.getMinutes()+3);
				document.cookie = "name="+name+";expires="+now.toGMTString();
				document.cookie = "count="+count+";expires="+now.toGMTString();			
				
			}
			else
			{
				var name = prompt("你的名字是谁?");
				var now = new Date();
				now.setMinutes(now.getMinutes()+3);
				document.cookie = "name="+name+";expires="+now.toGMTString();
				document.cookie = "count="+1+";expires="+now.toGMTString();			
				document.write("欢迎第一次光临!"+name)
			}
			

		</script>
		
	</body>
</html>
